package com.example.borui.partpositionproject.simple.partposition.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.borui.partpositionproject.simple.bean.DataBean;
import com.example.borui.partpositionproject.simple.utils.Utils;

/**
 * Created by borui on 2017/9/29.
 */
public class OneView extends FrameLayout {

    private TextView textView;

    public OneView(@NonNull Context context) {
        super(context);
        initView();
    }

    public OneView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public OneView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        textView = new TextView(getContext());
        addView(textView);
        FrameLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dip2px(getContext(), 100));
        textView.setLayoutParams(layoutParams);

        textView.setText("我是第一个分类");
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(0xff111111);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    }

    public  void initData(final DataBean dataBean, String content){
        FrameLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.dip2px(getContext(), 100));
        textView.setLayoutParams(layoutParams);

        textView.setText(content);
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(0xff111111);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

        if(null != dataBean){
            System.out.println("wo shi shen databean = " + dataBean.isCluster());
        }

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getContext(), "" + dataBean.getTextContent(), Toast.LENGTH_LONG).show();
            }
        });
    }
}
